home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume2 / uroff < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  6.4 KB

  1. From: ihnp4!amdcad!idi!bene!luke!itkin
  2. Subject: uroff - nroff underlining
  3. Reply-To: itkin@luke.UUCP (Steven List)
  4. Newsgroups: mod.sources
  5. Approved: john@genrad.UUCP
  6.  
  7. Mod.sources:  Volume 2, Issue 
  8. Submitted by: itkin@luke.UUCP (Steven List)
  9.  
  10.  
  11. Here's another little goodie from my toolbox.  I just couldn't stand it
  12. anymore - not having ANY highlighting at all in my documents.  Yes, we
  13. do have a daisywheel printer, but it's not on my system and it's too
  14. slow for drafts.  Now I can have underlining on my drafts! TA-DA!
  15.  
  16. As usual, send me comments and/or corrections and/or nasties.
  17. ------------------------------------------------------------------------
  18.  
  19. #! /bin/sh
  20. # This is a shell archive, meaning:
  21. # 1. Remove everything above the #! /bin/sh line.
  22. # 2. Save the resulting text in a file.
  23. # 3. Execute the file with /bin/sh (not csh) to create the files:
  24. #    uroff.c
  25. # This archive created: Thu Aug  1 18:33:02 1985
  26. export PATH; PATH=/bin:$PATH
  27. echo shar: extracting "'uroff.c'" '(4824 characters)'
  28. if test -f 'uroff.c'
  29. then
  30.     echo shar: will not over-write existing file "'uroff.c'"
  31. else
  32. sed 's/^    X//' << \SHAR_EOF > 'uroff.c'
  33.     X/*T uroff - produce nroff underlining for not-so-smart printers */
  34.     X/*S introduction */
  35.     X/*H uroff ----------------------------------------------------------- **
  36.     X**
  37.     X** uroff - produce underlining for nroff documents for printers that
  38.     X**            do not do backspacing.
  39.     X**
  40.     X** This program was written to reduce frustration with the use of the
  41.     X** Printronix P-series printers and nroff.  It was enough that we
  42.     X** couldn't have bold, italics, or anything resembling correspondence
  43.     X** or word-processing quality print.  But NO UNDERLINING either was too
  44.     X** much.  This program works with any printer that can handle text
  45.     X** followed by carriage return followed by some spaces and underscores.
  46.     X** Like the P-series with an IGP!
  47.     X**
  48.     X** This program is simple-minded, but quick.  It uses buffered I/O and
  49.     X** classes characters into very simple categories.
  50.     X**
  51.     X** usage: uroff [ file... ]
  52.     X**
  53.     X** If no file names are specified, it will filter standard input.
  54.     X** If a file name is dash (-), standard input will be read at that
  55.     X** point.
  56.     X**
  57.     X** Permission is granted for use and distribution, as long as you 
  58.     X** include the following notice:
  59.     X**
  60.     X** (c) 1985    Steven M. List
  61.     X**             Benetics Corporation, Mt. View, CA
  62.     X**             {cdp,greipa,idi,oliveb,sun,tolerant}!bene!luke!itkin
  63.     X**
  64.     X** ------------------------------------------------------------------ */
  65.     X/*E*/
  66.     X#include    <stdio.h>
  67.     X
  68.     Xchar    *pgm;
  69.     X
  70.     X#ifdef BSD
  71.     X#define strrchr rindex
  72.     X#endif
  73.     Xextern char *strrchr ();
  74.     X/*S main - control loop */
  75.     X/*Page Eject*/
  76.     Xmain (ac, av)
  77.     Xint        ac;
  78.     Xchar    **av;
  79.     X{
  80.     X    register FILE    *in;            /* input stream                */
  81.     X
  82.     X    /* ------------------------------------------------------------ */
  83.     X    /* set the basename of the program name for logging             */
  84.     X    /* ------------------------------------------------------------ */
  85.     X
  86.     X    if (pgm = strrchr (av[0], '/')) pgm++;
  87.     X    else pgm = av[0];
  88.     X
  89.     X    ac--; av++;
  90.     X
  91.     X    /* ------------------------------------------------------------ */
  92.     X    /* arguments are file names - if none, use standard input       */
  93.     X    /* ------------------------------------------------------------ */
  94.     X
  95.     X    if (ac == 0)
  96.     X    {
  97.     X        dofile (stdin);
  98.     X    }
  99.     X    else while (ac--)
  100.     X    {
  101.     X        if (!strcmp (*av, "-"))
  102.     X        {
  103.     X            in = stdin;
  104.     X        }
  105.     X        else if (!(in = fopen (*av, "r")))
  106.     X        {
  107.     X            fprintf (stderr,
  108.     X                "%s: cannot open %s for read\n", pgm, *(av-1));
  109.     X        }
  110.     X
  111.     X        av++;
  112.     X
  113.     X        if (in)
  114.     X        {
  115.     X            dofile (in);
  116.     X            if (in != stdin) fclose (in);
  117.     X        }
  118.     X    }
  119.     X
  120.     X    exit (0);
  121.     X}
  122.     X/*S dofile - process an input file */
  123.     X/*H dofile ***********************************************************
  124.     X*
  125.     X*                                   dofile
  126.     X*
  127.     X* Read each character from the input file.  Put it into the buffer
  128.     X* appropriate for the type.  Flush the buffers on newline or eof.
  129.     X*
  130.     X*********************************************************************/
  131.     X/*E*/
  132.     Xdofile (stream)
  133.     Xregister FILE *stream;
  134.     X{
  135.     X    /* ------------------------------------------------------------ */
  136.     X    /* some convenient defines                                      */
  137.     X    /* ------------------------------------------------------------ */
  138.     X
  139.     X#    define BUFSIZE 256
  140.     X#    define BACKSPACE '\b'
  141.     X#    define NEWLINE '\n'
  142.     X#    define FORMFEED '\f'
  143.     X#    define RETURN '\r'
  144.     X#    define UNDERSCORE '_'
  145.     X#    define TAB '\t'
  146.     X#    define SPACE ' '
  147.     X#    define NUL '\0'
  148.     X
  149.     X    register unsigned char anyund = 0;
  150.     X    register unsigned char backup = 0;
  151.     X    register char    c;
  152.     X    register int    i;
  153.     X    register char    *tp;
  154.     X    register char    *up;
  155.     X
  156.     X    char    tbuf[BUFSIZE];
  157.     X    char    ubuf[BUFSIZE];
  158.     X
  159.     X    /* ------------------------------------------------------------ */
  160.     X    /* initialize BOTH buffers to all spaces                        */
  161.     X    /* ------------------------------------------------------------ */
  162.     X
  163.     X    for (i = 0, tp = tbuf, up = ubuf; i < BUFSIZE; i++)
  164.     X        *(tp++) = *(up++) = SPACE;
  165.     X    tp = tbuf; up = ubuf;
  166.     X    
  167.     X    /* ------------------------------------------------------------ */
  168.     X    /* process each character in the input file                     */
  169.     X    /* ------------------------------------------------------------ */
  170.     X
  171.     X    while ((c = getc (stream)) != EOF)
  172.     X    {
  173.     X        switch (c)
  174.     X        {
  175.     X            case    BACKSPACE:
  176.     X                backup = 1;
  177.     X                break;
  178.     X            case    UNDERSCORE:
  179.     X                if (backup) *(up-1) = c;
  180.     X                else
  181.     X                {
  182.     X                    *up = c;
  183.     X                    up++; tp++;
  184.     X                }
  185.     X                anyund = 1;
  186.     X                backup = 0;
  187.     X                break;
  188.     X            case    NEWLINE:
  189.     X                *tp = *up = NUL;
  190.     X                fputs (tbuf, stdout);
  191.     X                if (anyund)
  192.     X                {
  193.     X                    putchar (RETURN);
  194.     X                    fputs (ubuf, stdout);
  195.     X                }
  196.     X                putchar (NEWLINE);
  197.     X                anyund = 0;
  198.     X                for (i = 0, tp = tbuf, up = ubuf; i < BUFSIZE; i++)
  199.     X                    *(tp++) = *(up++) = SPACE;
  200.     X                tp = tbuf; up = ubuf;
  201.     X                break;
  202.     X            case    SPACE:
  203.     X            case    TAB:
  204.     X            case    FORMFEED:
  205.     X                *(up++) = *(tp++) = c;
  206.     X                break;
  207.     X            default:
  208.     X                if (backup) *(tp-1) = c;
  209.     X                else
  210.     X                {
  211.     X                    *tp = c;
  212.     X                    up++; tp++;
  213.     X                }
  214.     X                backup = 0;
  215.     X                break;
  216.     X        }
  217.     X    }
  218.     X
  219.     X    if (tp != tbuf)
  220.     X    {
  221.     X        *tp = *up = NUL;
  222.     X        fputs (tbuf, stdout);
  223.     X        if (anyund)
  224.     X        {
  225.     X            putchar (RETURN);
  226.     X            fputs (ubuf, stdout);
  227.     X        }
  228.     X        putchar (NEWLINE);
  229.     X    }
  230.     X
  231.     X    return;
  232.     X}
  233. SHAR_EOF
  234. if test 4824 -ne "`wc -c < 'uroff.c'`"
  235. then
  236.     echo shar: error transmitting "'uroff.c'" '(should have been 4824 characters)'
  237. fi
  238. fi # end of overwriting check
  239. #    End of shell archive
  240. exit 0
  241.  
  242.  
  243.  
  244.